using System.Windows.Input;
using Bookvar.UI.Commands;

namespace Bookvar.UI.ViewModel
{
    public partial class AttachmentsWindowViewModel
    {
        private class DeleteAttachmentCommand : CommandModel
        {
            private readonly AttachmentsWindowViewModel viewModel;

            public DeleteAttachmentCommand( AttachmentsWindowViewModel viewModel )
                : base( BookvarCommands.DeleteAttachment )
            {
                this.viewModel = viewModel;
            }

            protected internal override void OnExecute( object sender, ExecutedRoutedEventArgs e )
            {
                var action = TopicActions.CreateDeleteAttachmentAction(
                    viewModel.SelectedAttachment, viewModel.Topic, viewModel.Mindmap );

                ActionService.Execute( action );
            }

            protected internal override void OnCanExecute( object sender, CanExecuteRoutedEventArgs e )
            {
                e.CanExecute = viewModel.SelectedAttachment != null;
                e.Handled = true;
            }
        }
    }
}